//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

int main(void)
{
    int fd;
    int version_no, size;
    time_t t;
    char ptr[128];
    int n;

    fd = open("version.txt", O_RDWR);

    if (fd == -1) {
        if (access("version.txt", F_OK) == 0)
            exit(1);
        else
            creat("version.txt", S_IRWXU);
        fd = open("version.txt", O_RDWR);
        if (fd == -1)
            exit(1);
    }

    size = lseek(fd, 0, SEEK_SET);
    size = lseek(fd, 0, SEEK_END);

    if (size == 0) {
        version_no = 1;
        lseek(fd, 0, SEEK_SET);
        write(fd, &version_no, 4);
    }
    else {
        lseek(fd, 0, SEEK_SET);
        read(fd, &version_no, 4);

        version_no++;
        lseek(fd, 0, SEEK_SET);
        write(fd, &version_no, 4);
    }
    printf("#define BlobBootLoaderVersion %d\n", version_no);

    t = time(&t);
    strcpy(ptr, ctime(&t));
    n = strlen(ptr);
// printf("%s\n", ptr);
    ptr[n-1] = '\0';

    printf("#define COMPILE_TIME_STAMP \"%s\"\n", ptr);

    close(fd);
}
